<?php

namespace App\Models;

class Navbars extends Base
{
    protected $table = 'navbars';

    const TARGET_1 = 1;
    const TARGET_2 = 2;

    const TARGET_TEXT = [
        self::TARGET_1 => '<span class="el-tag  el-tag--danger">是</span>',
        self::TARGET_2 => '<span class="el-tag">否</span>',
    ];

    protected $fillable = [
        'id','title','link','sort','target','created_at','updated_at'
    ];

    /**
     * 获取列表
     * @param array $params 条件参数
     * @param array $fields 查询的字段
     * @return mixed
     */
    protected function getList($params = [], $fields = ['*']){
        $lists = $this->select($fields)
            ->where(function ($query) use ($params) {
                if(isset($params['kwd']) && $params['kwd']) {
                    $query ->where('title','like','%' . $params['kwd'] . '%');
                }
            })->orderBy('sort', 'asc')
            ->get();
        $this->stateToText($lists,[
            'target' => self::TARGET_TEXT,
        ]);
        return $lists;
    }

}
